package com.ruoyi.warehouse.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.domain.ZnWarehouse;
import com.ruoyi.warehouse.service.IZnWarehouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 仓库信息管理Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/warehouse/warehouse")
public class ZnWarehouseController extends BaseController
{
    @Autowired
    private IZnWarehouseService znWarehouseService;

    /**
     * 查询仓库信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:list')")
    @GetMapping("/list")
    public AjaxResult list(ZnWarehouse znWarehouse)
    {
        List<ZnWarehouse> list = znWarehouseService.selectZnWarehouseList(znWarehouse);
        return success(list);
    }

    /**
     * 导出仓库信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:export')")
    @Log(title = "仓库信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnWarehouse znWarehouse)
    {
        List<ZnWarehouse> list = znWarehouseService.selectZnWarehouseList(znWarehouse);
        ExcelUtil<ZnWarehouse> util = new ExcelUtil<ZnWarehouse>(ZnWarehouse.class);
        util.exportExcel(response, list, "仓库信息管理数据");
    }

    /**
     * 获取仓库信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(znWarehouseService.selectZnWarehouseById(id));
    }

    /**
     * 新增仓库信息管理
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:add')")
    @Log(title = "仓库信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnWarehouse znWarehouse)
    {
        return toAjax(znWarehouseService.insertZnWarehouse(znWarehouse));
    }

    /**
     * 修改仓库信息管理
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:edit')")
    @Log(title = "仓库信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnWarehouse znWarehouse)
    {
        return toAjax(znWarehouseService.updateZnWarehouse(znWarehouse));
    }

    /**
     * 删除仓库信息管理
     */
    @PreAuthorize("@ss.hasPermi('warehouse:warehouse:remove')")
    @Log(title = "仓库信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(znWarehouseService.deleteZnWarehouseByIds(ids));
    }
}
